package entity.CRM;

import entity.Employee;
import entity.FRM.CreditAccount;
import entity.FRM.CustomerInvoice;
import entity.FRM.CustomerPayment;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

@Entity
public class Customer extends SaleLead implements Serializable {
    @OneToOne
    private CreditAccount creditAccount;

    @OneToMany
    private List<SaleOrder> saleOrders = new ArrayList<SaleOrder>();
    @OneToMany
    private List<CustomerInvoice> customerInvoices = new ArrayList<CustomerInvoice>();
    @OneToMany
    private List<CustomerPayment> customerPayments = new ArrayList<CustomerPayment>();
    
 

    public List<SaleOrder> getSaleOrders() {
        return saleOrders;
    }

    public void setSaleOrders(List<SaleOrder> saleOrders) {
        this.saleOrders = saleOrders;
    }

    public CreditAccount getCreditAccount() {
        return creditAccount;
    }

    public void setCreditAccount(CreditAccount creditAccount) {
        this.creditAccount = creditAccount;
    }

    public List<CustomerInvoice> getCustomerInvoices() {
        return customerInvoices;
    }

    public void setCustomerInvoices(List<CustomerInvoice> customerInvoices) {
        this.customerInvoices = customerInvoices;
    }
    
    
    public List<SaleOrder> getSaleOrdersWithCIA() {
        List<SaleOrder> temp=new ArrayList<SaleOrder>();
        for(SaleOrder temp_SaleOrder:this.getSaleOrders())
        {
            if ((temp_SaleOrder.getCashInAdvance()!=null) && (temp_SaleOrder.getCashInAdvance().getCashInAdvanceAmount()>0))
                temp.add(temp_SaleOrder);
        }
        return temp;
    }
    
    public List<SaleOrder> getSaleOrder_Pending()
    {
        List<SaleOrder> temp_SaleOrders = new ArrayList<SaleOrder>();
        for (SaleOrder temp: this.getSaleOrders())
            if (temp.getStateSaleOrder()==SaleOrder.StateSaleOrder.Pending)
                    temp_SaleOrders.add(temp);
        return temp_SaleOrders;
    }
    
    public List<SaleOrder> getSaleOrder_Confirmed()
    {
        List<SaleOrder> temp_SaleOrders = new ArrayList<SaleOrder>();
        for (SaleOrder temp: this.getSaleOrders())
            if (temp.getStateSaleOrder()==SaleOrder.StateSaleOrder.Confirmed)
                    temp_SaleOrders.add(temp);
        return temp_SaleOrders;
    }

    public List<CustomerPayment> getCustomerPayments() {
        return customerPayments;
    }

    public void setCustomerPayments(List<CustomerPayment> customerPayments) {
        this.customerPayments = customerPayments;
    }
    
    public List<CustomerInvoice> getCustomerInvoice_Pending()
    {
        List<CustomerInvoice> temp_CustomerInvoices = new ArrayList<CustomerInvoice>();
        for (CustomerInvoice temp:this.getCustomerInvoices())
        {
            if (temp.getStateCustomerInvoice() == CustomerInvoice.StateCustomerInvoice.Pending)
                temp_CustomerInvoices.add(temp);
        }
        return temp_CustomerInvoices;
    }
}
